import React,{useState,useRef} from 'react'
import {TodolistContext} from './context'


const Input = () => {
    const [val,setVal] = useState('1234');
    const inpRef = useRef();
    return (
        <div>
            <input 
                ref={inpRef}
                value={val}
                onChange={e=>setVal(e.target.value)}
                type="text" />
            <button onClick={()=>{console.log(inpRef.current.value)}}>添加1</button>
            <TodolistContext.Consumer>
                {
                    ({addItem})=><button onClick={()=>addItem(val)}>添加</button>
                }
            </TodolistContext.Consumer>
        </div>
    )
}
export default Input